package com.administrator.cloudapplication.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.administrator.cloudapplication.R;
import com.administrator.cloudapplication.models.BankModel;
import com.administrator.cloudapplication.models.WeatherModel;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/4/27.
 */

public class WeatherAdapter extends BaseAdapter {
    Context mContext;
    ArrayList<WeatherModel.ResultsBean.WeatherDataBean> mDataBean = new ArrayList<>();
    ArrayList<BankModel.PointListBean> mBankDataBean = new ArrayList<>();
    LayoutInflater mInflater;
    int type;
    public WeatherAdapter(Activity activity, ArrayList<WeatherModel.ResultsBean.WeatherDataBean>
            dataBean, ArrayList<BankModel.PointListBean> bankDataBean, int type) {
        mContext = activity;
        mDataBean = dataBean;
        mBankDataBean = bankDataBean;
        mInflater = LayoutInflater.from(activity);
        this.type=type;
    }

    @Override
    public int getCount() {
        switch (type) {
            case 0:
                return mDataBean.size();
            case 1:
                return mBankDataBean.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int i) {

        switch (type) {
            case 0:
                return mDataBean.get(i);
            case 1:
                return mBankDataBean.get(i);
        }
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    private class ViewHolder {
        ImageView img;
        TextView tv_top_left;
        TextView tv_top_right;
        TextView tv_wind;
        TextView tv_temperature;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            switch (type) {
                case 0:
                    view = mInflater.inflate(R.layout.view_weather_item, null);
                    holder.tv_top_left = (TextView) view.findViewById(R.id.tv_left);
                    holder.tv_top_right = (TextView) view.findViewById(R.id.tv_right);
                    holder.tv_wind = (TextView) view.findViewById(R.id.tv_wind);
                    holder.tv_temperature = (TextView) view.findViewById(R.id.tv_temp);
                    break;
                case 1:
                    view = mInflater.inflate(R.layout.view_bank_item, null);
                    holder.tv_top_left = (TextView) view.findViewById(R.id.tv_one);
                    holder.tv_top_right = (TextView) view.findViewById(R.id.tv_two);
                    holder.tv_wind = (TextView) view.findViewById(R.id.tv_three);
                    break;
            }
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        switch (type) {
            case 0:
                WeatherModel.ResultsBean.WeatherDataBean mBean = (WeatherModel.ResultsBean.WeatherDataBean) getItem(i);
                holder.tv_top_left.setText(mBean.getDate());
                holder.tv_top_right.setText(mBean.getWeather());
                holder.tv_wind.setText(mBean.getWind());
                holder.tv_temperature.setText(mBean.getTemperature());
                break;
            case 1:
                BankModel.PointListBean mBankBean = (BankModel.PointListBean) getItem(i);
                holder.tv_top_left.setText(mBankBean.getDistrict());
                holder.tv_top_right.setText(mBankBean.getName());
                holder.tv_wind.setText(mBankBean.getAddress());
                break;
        }
        return view;
    }
}
